﻿

namespace DBA.Data.ADO
{
    /// <summary>
    /// 根据数据驱动类型，建立数据访问函数库的工厂
    /// </summary>
    public static class ADOFactory
	{
        /// <summary>
        /// 根据web.config里的默认值实例化
        /// </summary>
        /// <returns></returns>
        public static DataAccessLibrary CreateDAL()
        {
            DataAccessLibrary myDAL ;

            switch (CommonFactory.ProviderName)
            {
                case "System.Data.SqlClient":     //SqlClient "System.Data.SqlClient"
                    myDAL = new SqlClientDAL();
                    break;

                default :     //OleDb
                    myDAL = new OleDbDAL();
                    break;

                case "System.Data.Odbc":     //Odbc
                    myDAL = new OdbcDAL();
                    break;

                case "System.Data.OracleClient":
                    myDAL = new OracleClientDAL();
                    break;
            }

            return myDAL;
        }

        public static DataAccessLibrary CreateDAL(DBA.Data.Hibernate.NHibernateQuery nhbQuery)
        {
            DataAccessLibrary myDAL;

            switch (CommonFactory.ProviderName)
            {
                case "System.Data.SqlClient":     //SqlClient "System.Data.SqlClient"
                    myDAL = new SqlClientDAL(nhbQuery);
                    break;

                default:     //OleDb
                    myDAL = new OleDbDAL();
                    break;

                case "System.Data.Odbc":     //Odbc
                    myDAL = new OdbcDAL();
                    break;

                case "System.Data.OracleClient":
                    myDAL = new OracleClientDAL();
                    break;
            }

            return myDAL;
        }

        /// <summary>
        /// 创建与web.config的默认设置不同的help
        /// </summary>
        /// <param name="connectionString">连接字符串</param>
        /// <param name="providerName">数据库驱动的名称。System.Data.SqlClient、System.Data.OleDb 、System.Data.Odbc、System.Data.OracleClient等</param>
        /// <returns></returns>
        public static DataAccessLibrary CreateDAL(string connectionString, string providerName)
        {
            DataAccessLibrary myDAL;

            switch (providerName)
            {
                case "System.Data.SqlClient":     //SqlClient "System.Data.SqlClient"
                    myDAL = new SqlClientDAL(connectionString, providerName);
                    break;

                default:     //OleDb
                    myDAL = new OleDbDAL(connectionString, providerName);
                    break;

                case "System.Data.Odbc":     //Odbc
                    myDAL = new OdbcDAL(connectionString, providerName);
                    break;

                case "System.Data.OracleClient":
                    myDAL = new OracleClientDAL(connectionString, providerName);
                    break;
            }

            return myDAL;
        }
	}
}
